/** @file ViewCommand
    @class ViewCommand
    @brief Command that rotates a game object and pitches its camera node
*/
#ifndef __ViewCommand_h_
#define __ViewCommand_h_

#include "Command.h"

class ViewCommand : public Command {
public:
	/**
	* The constructor
	*/
	ViewCommand (float turn, float pitchCamera, unsigned int playerId)
		: Command(playerId), m_turn(turn), m_pitchCamera(pitchCamera) {}
	
	/**
	* The empty constructor
	*/
	ViewCommand() {}
	
	/**
	* The deconstructor
	*/
	virtual ~ViewCommand (void) {}
	
	/**
	* Executs the command on argument model
	*/
	virtual bool execute(Model *model) {
		GameObject *gameObject = model->getByID(getPlayerId());
		if ( gameObject == NULL) {
			return false;
		} else {
			dynamic_cast<PlayerAvatar*>(gameObject)->turn(m_turn);
			dynamic_cast<PlayerAvatar*>(gameObject)->pitchCamera(m_pitchCamera);
			return true;
		}
	}
	
	/**
	* Saves the command to a output file stream
	*/
	virtual void save(ofstream &ofs) {
		int i = VIEWCOMMAND;
		ofs.write((char*) &i, sizeof(int));
		Command::save(ofs);
		ofs.write((char*) &m_turn, sizeof(float));
		ofs.write((char*) &m_pitchCamera, sizeof(float));
  }

	/**
	* Loads a command from a input file stream
	*/
  virtual void load(ifstream &ifs) {
		Command::load(ifs);
		ifs.read((char*) &m_turn, sizeof(float));
		ifs.read((char*) &m_pitchCamera, sizeof(float));
  }

	/**
	* Saves the command to a bit stream
	*/
	virtual void save(RakNet::BitStream &ofs) {
		int i = VIEWCOMMAND;
		ofs.Write((char*) &i, sizeof(int));
		Command::save(ofs);
		ofs.Write((char*) &m_turn, sizeof(float));
		ofs.Write((char*) &m_pitchCamera, sizeof(float));
	}
	
	/**
	* Loads a command from a bit stream
	*/
	virtual void load(RakNet::BitStream &ifs) {
		Command::load(ifs);
		ifs.Read((char*) &m_turn, sizeof(float));
		ifs.Read((char*) &m_pitchCamera, sizeof(float));
	}

private:
	/**
	* How many degrees the game object should turn
	*/
	float m_turn;
	
	/**
	* How many degrees the game objects camera node should be pitced
	*/
	float m_pitchCamera;
};

#endif